package com.juice.utils;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/4/15 12:28 上午
 */

import java.util.Objects;

/**
 * Description:
 *
 * @author: rls
 * @Date: 2017-11-05 20:46
 */
public class Pair<FIRST, SECOND> {

    /**
     * first
     */
    private FIRST first;

    /**
     * second
     */
    private SECOND second;

    public Pair() {

    }

    /**
     * Pair
     *
     * @param first
     * @param second
     */
    private Pair(FIRST first, SECOND second) {
        this.first = first;
        this.second = second;
    }

    /**
     * getFirst
     *
     * @return
     */
    public FIRST getFirst() {
        return first;
    }

    /**
     * getSecond
     *
     * @return
     */
    public SECOND getSecond() {
        return second;
    }

    /**
     * <p>Compares this triple to another based on the three elements.</p>
     *
     * @param obj the object to compare to, null returns false
     * @return true if the elements of the triple are equal
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj instanceof Pair<?, ?>) {
            final Pair<?, ?> other = (Pair<?, ?>) obj;
            return Objects.equals(getFirst(), other.getFirst())
                    && Objects.equals(getSecond(), other.getSecond());
        }
        return false;
    }


    /**
     * <p>Returns a suitable hash code.</p>
     *
     * @return the hash code
     */
    @Override
    public int hashCode() {
        return (getFirst() == null ? 0 : getFirst().hashCode()) ^
                (getSecond() == null ? 0 : getSecond().hashCode());
    }


    /**
     * of
     *
     * @param first
     * @param second
     * @param <F>
     * @param <S>
     * @return
     */
    public static final <F, S> Pair<F, S> of(F first, S second) {
        return new Pair<>(first, second);
    }
}

